﻿<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WF_ProcessDefined_Coding.aspx.vb"
    Inherits="MyWorkflow.WF_ProcessDefined_Coding" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head id="Head1" runat="server">
    <title></title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <link href="/_common/styles/global.css" type="text/css" rel="stylesheet">
    <script language="javascript" src="/_common/scripts/global.js"></script>
    <!-- Menu -->
    <link href="/_nav/menu.css" type="text/css" rel="stylesheet">
    <!-- Form -->
    <link href="/_forms/styles/form.css" type="text/css" rel="stylesheet">
    <script language="javascript" src="/_forms/FormBase.js"></script>
    <script language="javascript" src="/_controls/number/number.js"></script>
    <!-- Select -->
    <link href="/_common/styles/select.css" type="text/css" rel="stylesheet">
    <!-- Utility-->
    <script language="javascript" src="/_controls/util/util.js"></script>
    <script language="javascript" src="/_grid/rep_grid.js"></script>
    <link href="/_grid/map_grid.css" type="text/css" rel="stylesheet">
    <script language="javascript" src="/MyWorkflow/Workflow.js"></script>
    <script type="text/javascript">
            var arrSelected;
            var type;
            window.onload = function() {
                var xmlDoc = window.dialogArguments; //debugger;
                type = $id("__type").value;
                if (type == 0) { $id("codeNumber").style.display = ""; } //BUG 46963 SUNFX 2009-9-2 END

                var nodes = xmlDoc.selectNodes("/BusinessType/Item/Domain");
                if (nodes.length > 0) {
                    for (var i = 0; i < nodes.length; i++) {
                        var name = nodes[i].attributes.getNamedItem("name").value
                        var otr = Table1.insertRow();
                        otr.oid = "[" + name + "]";
                        otr.value = name;
                        otr.height = "21";
                        otr.allowselect = "1";
                        otr.is_hide = "false";
                        otr.ondblclick = appendSelected;
                        otr.onmouseover = function() { this.bgColor = "#E3E9F4"; }
                        otr.onmouseout = function() { this.bgColor = "#ffffff"; }
                        var otd = otr.insertCell()
                        otd.innerHTML = name;
                        otd.style.paddingLeft = "3px";
                        otd.style.whiteSpace = 'nowrap';
                    }
                } else {
                    document.getElementById("trTitle").style.display = "none";
                }

                if (document.all("Table1")) {
                    initGrid(Table1);
                }

                if (document.all("tblSelected")) {
                    initGrid(tblSelected);
                }

                var cr = document.getElementById("__cr").value;
                var arrcr;
                if (type == 1 && (cr == "" || cr == "undefined")) //BUG 46963 SUNFX 2009-9-2 END
                {
                    cr = "$流水号$~";
                }

                var inpall = document.getElementById("inpAll");
                inpall.coding = cr;
                inpall.value = codingShow(cr);
                arrcr = cr.split("~");
                var id, oid, sep;
                for (var i = 0; i < arrcr.length - 1; i++) {
                    _id = i + 1;
                    oid = getCoding(arrcr[i]);
                    sep = arrcr[i].replace(oid, "");
                    codingToList(_id, oid, sep);
                }
                setSeparator();
            }
			
			//功能：向列表添加编码关键字
			function codingToList(_id,oid,sep)
			{
			    var targetTable = tblSelected;
			    
			    var objAddRow;
				var objAddCell;
				
				objAddRow = targetTable.insertRow();
				objAddRow.height = "21px";
				objAddRow.oid = oid;
				objAddRow.value = getCodingText(oid);
				//objAddRow.ondblclick = removeSelected;
				
				objAddCell0 = objAddRow.insertCell(0);
		        objAddCell1 = objAddRow.insertCell(1);
		        objAddCell2 = objAddRow.insertCell(2);
				
				with(objAddCell0)
				{
					align = "center";		
					innerHTML = _id;
					className="item";
				}
				with(objAddCell1)
				{
					align = "left";
					if (oid.indexOf("#") >= 0) {
					    //BUG 46685 编号填写尖括号后，发起流程会出错，填写单引号后，修改时单引号后的文字被截断 sunfx 2009年4月28日16:32:21
					    innerHTML = "<input type='text' maxLength='30' forbiddenChars=\"'#%$[]~&<>\" value='" + objAddRow.value + "' onblur='input_onchange(this)' />";
					    //BUG 46685 END
					}
					else{
					    innerHTML = objAddRow.value;
					}
					className="item";
				}
				with(objAddCell2)
				{
					align = "center";
					if (type == 0 || oid != "$流水号$") //BUG 46963 SUNFX 2009-9-2 END
					    //BUG 46685 BEGIN
					    innerHTML = "<input type='text' maxLength='1' forbiddenChars=\"'#%$[]~&<>\" value='" + sep + "' style='text-align:center;' onchange='changeCoding()' />";
					else
					    innerHTML = "<input type='text' maxLength='1' forbiddenChars=\"'#%$[]~&<>\" readonly value='" + sep + "' style='text-align:center;border:1px #CCCCCC solid' onchange='changeCoding()' />";
					    //BUG 46685 END
					className="item";
				}
				
			}
			//功能：提前编码关键字
			function getCoding(str)
			{
			    if(str.indexOf("[") >=0)
			    {
			        return str.match(/\[.+\]/g)[0];
			    }
			    
			    if(str.indexOf("#") >=0)
			    {
			        return str.match(/\#.*\#/g)[0];
			    }
			    
			    if(str.indexOf("$") >=0)
			    {
			        return str.match(/\$.+\$/g)[0];
			    }
			    
			    if(str.indexOf("%") >=0)
			    {
			        return str.match(/\%.+\%/g)[0];
			    }
			}
			//功能：将编码关键字替换成显示文本
			function getCodingText(str)
			{
			    return str.replace(/\[/g,"").replace(/\]/g,"").replace(/\#/g,"").replace(/\$/g,"").replace(/\%/g,"");
			}
            //功能：设置分隔符
			function setSeparator() {
			    if (type == 0) {
				    if (tblSelected.rows.length > 1) {
				        var lastCell = tblSelected.rows[tblSelected.rows.length - 1].cells[2];
				        lastCell.firstChild.readOnly = true;
				        lastCell.firstChild.style.borderColor = '#CCCCCC';
				        lastCell.firstChild.value = '';
				    }
				    if (tblSelected.rows.length > 2) {
				        lastCell = tblSelected.rows[tblSelected.rows.length - 2].cells[2];
				        lastCell.firstChild.readOnly = false;
				        lastCell.firstChild.style.borderColor = '';
				        if (lastCell.firstChild.value == '') { lastCell.firstChild.value = '-'; }
				    }
				}
			}
		    
		    function verfiyDomainName(name)
		    {
		        var forbiddenChars = "()[]{}";
		        for (var i = 0; i < forbiddenChars.length; i++)
		        {
			        if (name.indexOf(forbiddenChars.charAt(i)) >= 0)
			        {
				        alert("当前选择数据域包含“" + forbiddenChars.charAt(i) + "”字符，不能作为编码规则！");
		                return false;
			        }
			    }
		        
		        return true;
		    }
			//功能：向已选项中添加选中的待选项
			function appendSelected()
			{
				boolInit = false;
				var arrTr = getSelectedTr("Table1");
				//校验域名称中的特殊字符
				if (!verfiyDomainName(arrTr[0].value)) return false;
				addTargetRow(arrTr);
			}
			
			
			
			//功能：从已选项中移除选中项
			function removeSelected()
			{
				var targetTable = tblSelected;
				
				for(var i=targetTable.rows.length-1;i>=1;i--)
				{
					if(targetTable.rows[i].selected) 
					{
					    if(type == 0 || targetTable.rows[i].oid!="$流水号$") //BUG 46963 SUNFX 2009-9-2 END
						    targetTable.deleteRow(i);
					}
				}
				
				for(var i=1;i<=targetTable.rows.length-1;i++)
				{
					targetTable.rows[i].cells[0].innerHTML = i;
				}

				setSeparator();
				changeCoding();
			}
			
			//功能：向已选列表中添加行集合
			function addTargetRow(arrTr)
			{
				var targetTable = tblSelected;
				var selectedRows;
				for(var i=0;i<arrTr.length;i++)
				{
					if(!arrTr[i].oid) continue;
					
					var bExists = false;
					for(var j=1;j<targetTable.rows.length;j++)
					{
						if(targetTable.rows[j].oid==arrTr[i].oid)
						{
							bExists = true;
							break;
						}
					}
					
					if(!bExists)
					{
					    //上一选项分隔符赋默认值
				        //var txtSep = targetTable.rows[tblSelected.rows.length - 1].cells[2].getElementsByTagName("input")[0];
				        //if(txtSep){
				       //     txtSep.value = "-";
				       // }
					
						var objAddRow;
						var objAddCell;
						var rowCount = targetTable.rows.length;

						objAddRow = targetTable.insertRow(rowCount - type); //BUG 46963 SUNFX 2009-9-2 END
						objAddRow.height = "21px";
						objAddRow.oid = arrTr[i].oid;
						objAddRow.value = arrTr[i].value;
						//objAddRow.ondblclick = removeSelected;
						
						objAddCell0 = objAddRow.insertCell(0);
				        objAddCell1 = objAddRow.insertCell(1);
				        objAddCell2 = objAddRow.insertCell(2);
						
						with(objAddCell0)
						{
						    align = "center";
						    innerHTML = rowCount - type; //BUG 46963 SUNFX 2009-9-2 END
							className="item";
						}
						with(objAddCell1)
						{
							align = "left";		
							innerHTML = arrTr[i].value;
							className="item";
						}
						with(objAddCell2)
						{
						    align = "center";
						    //BUG 46685 BEGIN
						    //BUG 46963 SUNFX 2009-9-2 END
						    innerHTML = "<input type='text' maxLength='1' forbiddenChars=\"'#%$[]~&<>\" value='-' style='text-align:center;' onchange='changeCoding();' />";
						    //BUG 46685 END
							className="item";
						}
						rowCount = targetTable.rows.length;
						targetTable.rows[rowCount-1].cells[0].innerText = rowCount-1;
		            }
		            setSeparator();
					changeCoding();
				}
			}
			
			//功能：增加文本
			function appendText(){
			    var objAddRow;
				var objAddCell;
				
				//上一选项分隔符
				//var txtSep = tblSelected.rows[tblSelected.rows.length - 1].cells[2].getElementsByTagName("input")[0];
				//if(txtSep){
				//    txtSep.value = "-";
				//}
				var rowCount = tblSelected.rows.length;
				objAddRow = tblSelected.insertRow(rowCount - type); //BUG 46963 SUNFX 2009-9-2 END
				objAddRow.height = "21px";
				objAddRow.oid = "##";
				objAddRow.value = "";
				//objAddRow.ondblclick = removeSelected;
				
				objAddCell0 = objAddRow.insertCell(0);
				objAddCell1 = objAddRow.insertCell(1);
				objAddCell2 = objAddRow.insertCell(2);
				
				with(objAddCell0)
				{
				    align = "center";
				    innerHTML = rowCount - type; //BUG 46963 SUNFX 2009-9-2 END
					className="item";
				}
				with(objAddCell1)
				{
				    align = "left";
				    //BUG 46685 BEGIN
				    innerHTML = "<input type='text' maxLength='30' forbiddenChars=\"'#%$[]~&<>\" value='' onblur='input_onchange(this)' />";
				    //BUG 46685 END
					className="item";
				}
				with(objAddCell2)
				{
				    align = "center";
				    //BUG 46685 BEGIN
				    //BUG 46963 SUNFX 2009-9-2 END
				    innerHTML = "<input type='text' maxLength='1' forbiddenChars=\"'#%$[]~&<>\" value='-' style='text-align:center;' onchange='changeCoding();' />";
				    //BUG 46685 END
					className="item";
				}
				tblSelected.rows[rowCount].cells[0].innerText = rowCount;
				tblSelected.rows[rowCount - type].cells[1].firstChild.focus(); //BUG 46963 SUNFX 2009-9-2 END
				setSeparator();
				changeCoding();
			}
			
			//功能：上移
			function action_up(){
			    var targetTable = tblSelected;
			    var temp;
			    for(var i=targetTable.rows.length-1;i>=2;i--)
				{
					if(targetTable.rows[i].selected) 
					{
						var selectedRow = targetTable.rows[i];
						var _selectedRow = targetTable.rows[i-1];

						if (type == 1 && (selectedRow.oid == "$流水号$" || _selectedRow.oid == "$流水号$")) return; //BUG 46963 SUNFX 2009-9-2 END
						
						temp = selectedRow.oid;
						selectedRow.oid = _selectedRow.oid;
						_selectedRow.oid = temp;
						temp = selectedRow.cells[1].innerHTML;
						selectedRow.cells[1].innerHTML = _selectedRow.cells[1].innerHTML;
						_selectedRow.cells[1].innerHTML = temp;
						temp = selectedRow.cells[2].innerHTML;
						selectedRow.cells[2].innerHTML = _selectedRow.cells[2].innerHTML;
						_selectedRow.cells[2].innerHTML = temp;
						selectRow(targetTable,_selectedRow);
						unselectRow(targetTable, selectedRow);
						setSeparator();
						changeCoding();
						return;
					}
				}
			}
			
			//功能：下移
			function action_down(){
			    var targetTable = tblSelected;
			    var temp;
			    for(var i=1;i<=targetTable.rows.length-2;i++)
				{
					if(targetTable.rows[i].selected) 
					{
						var selectedRow = targetTable.rows[i];
						var _selectedRow = targetTable.rows[i+1];

						if (type == 1 && (selectedRow.oid == "$流水号$" || _selectedRow.oid == "$流水号$")) return; //BUG 46963 SUNFX 2009-9-2 END
						
						temp = selectedRow.oid;
						selectedRow.oid = _selectedRow.oid;
						_selectedRow.oid = temp;
						temp = selectedRow.cells[1].innerHTML;
						selectedRow.cells[1].innerHTML = _selectedRow.cells[1].innerHTML;
						_selectedRow.cells[1].innerHTML = temp;
						temp = selectedRow.cells[2].innerHTML;
						selectedRow.cells[2].innerHTML = _selectedRow.cells[2].innerHTML;
						_selectedRow.cells[2].innerHTML = temp;
						selectRow(targetTable,_selectedRow);
						unselectRow(targetTable, selectedRow);
						setSeparator();
						changeCoding();
						return;
					}
				}
			}
			
			//功能：返回
			function okClick()
			{
			    var coding = document.getElementById("inpAll").coding;
			    if(coding.length > 200){
			        alert("编辑规则必须小于200字符！")
			        return;
			    }
			    
			    var targetTable = tblSelected;
			    var oid;
			    for(var i=1;i<=targetTable.rows.length-1;i++)
				{
				    oid = targetTable.rows[i].oid;
				    if(oid.search(/\#.*\#/) != -1)
				    {
					    if(targetTable.rows[i].cells[1].firstChild.value == ""){
					        alert("文本不能为空！");
					        targetTable.rows[i].cells[1].firstChild.focus();
					        return;
					    }
					}
				}
				openWaiting();				
				window.returnValue = coding;				
				window.close();
			}
			
			//功能：改变编码规则
			function changeCoding()
			{   
			    var targetTable = tblSelected;
			    var inpall = document.getElementById("inpall");
			    var inpallvalue = "";
			    var oid;
			    for(var i=1;i<=targetTable.rows.length-1;i++)
				{
				    oid = targetTable.rows[i].oid;
				    if(oid.search(/\#.*\#/) != -1)
				    {
					    inpallvalue += "#" + targetTable.rows[i].cells[1].firstChild.value + "#";
					}
					else{
					    inpallvalue += targetTable.rows[i].oid;
					}
					inpallvalue += targetTable.rows[i].cells[2].firstChild.value + "~";
				}
				inpall.value = codingShow(inpallvalue);
				inpall.coding = inpallvalue;
			}
			
			function input_onchange(o){
		        changeCoding();
			}
			
    </script>
    <style>
        .bar
        {
	        border: 1px solid #C5C1B1;
	        border-bottom: 1px solid #C5C1B1;
	        border-right: 1px solid #C5C1B1;
	        background-color: #E9E7D7;
	        table-layout: fixed;
        }
        .item
        {
	         border-bottom:1px solid #C5C1B1;
	         padding-left:3px;
	         white-space:nowrap;
        }
        .item input
        { 
            width:90%;
            height:18px;
        }
    </style>
</head>
<body ms_positioning="GridLayout">
    <form id="mapForm" method="post" runat="server">
    <asp:TextBox ID="txtMyModules" Style="display: none" runat="server"></asp:TextBox>
    <table style="table-layout: fixed" height="100%" cellspacing="0" cellpadding="0"
        width="100%" border="0">
        <tr>
            <td width="5">
            </td>
            <td style="padding-top: 5px" valign="top">
                <table height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">
                    <tr height="5">
                        <td colspan="3">
                        </td>
                    </tr>
                    <tr height="340">
                        <td class="wizbox1" valign="top" width="40%">
                            <table style="font-size: 9pt" height="100%" cellspacing="0" cellpadding="0" width="100%">
                                <tr height="1">
                                    <td>
                                        <mnu:AppGridMenu ID="appGridMenu1" runat="server"></mnu:AppGridMenu>
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        <div id="divList" style="overflow: auto; width: 100%; height: 100%">
                                            <table id="Table1" onclick="handleClick();" cellspacing="0" cellpadding="0" border="0"
                                                style="font-size: 9pt; width: 100%; font-family: 宋体; border-collapse: collapse;
                                                table-layout: fixed" width="100%" MultiSelect="true">
                                                <tr height="0px">
                                                    <td>
                                                    </td>
                                                </tr>
                                                <tr height="21" oid="$公司名称$" value="公司名称" allowselect="1" is_hide="false" ondblclick="appendSelected();"
                                                    onmouseover="this.bgColor=&quot;#E3E9F4&quot;" onmouseout="this.bgColor=&quot;#ffffff&quot;">
                                                    <td style="padding-left: 3px;" nowrap>
                                                        公司名称
                                                    </td>
                                                </tr>
                                                <tr height="21" oid="$公司代码$" value="公司代码" allowselect="1" is_hide="false" ondblclick="appendSelected();"
                                                    onmouseover="this.bgColor=&quot;#E3E9F4&quot;" onmouseout="this.bgColor=&quot;#ffffff&quot;">
                                                    <td style="padding-left: 3px;" nowrap>
                                                        公司代码
                                                    </td>
                                                </tr>
                                                <tr height="21" oid="$年$" value="年" allowselect="1" is_hide="false" ondblclick="appendSelected();"
                                                    onmouseover="this.bgColor=&quot;#E3E9F4&quot;" onmouseout="this.bgColor=&quot;#ffffff&quot;">
                                                    <td style="padding-left: 3px;" nowrap>
                                                        年
                                                    </td>
                                                </tr>
                                                <tr height="21" oid="$月$" value="月" allowselect="1" is_hide="false" ondblclick="appendSelected();"
                                                    onmouseover="this.bgColor=&quot;#E3E9F4&quot;" onmouseout="this.bgColor=&quot;#ffffff&quot;">
                                                    <td style="padding-left: 3px;" nowrap>
                                                        月
                                                    </td>
                                                </tr>
                                                <tr id="codeNumber" style="display:none" height="21" oid="$流水号$" value="流水号" allowselect="1" is_hide="false" ondblclick="appendSelected();"
                                                    onmouseover="this.bgColor=&quot;#E3E9F4&quot;" onmouseout="this.bgColor=&quot;#ffffff&quot;">
                                                    <td style="padding-left: 3px;" nowrap>
                                                        流水号
                                                    </td>
                                                </tr>
                                                <tr id="trTitle" allowselect="0">
                                                    <td>
                                                        <mnu:AppGridMenu ID="appGridMenu2" runat="server"></mnu:AppGridMenu>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td align="center" width="80px">
                            <p>
                                <button id="Button1" title="增加文本" style="width: 60px" onclick="appendText()" type="button">
                                    增加文本</button></p>
                            <p>
                                <button id="btnAppendAll" title="添加关键字" style="width: 60px" onclick="appendSelected()"
                                    type="button">
                                    &gt;&gt;</button></p>
                            <p>
                                <button id="btnRemoveAll" title="移除关键字" style="width: 60px" onclick="removeSelected();"
                                    type="button">
                                    &lt;&lt;</button></p>
                        </td>
                        <td class="wizbox1" valign="top" width="42%">
                            <table style="font-size: 9pt" height="100%" cellspacing="0" cellpadding="0" width="100%">
                                <tr height="1">
                                    <td>
                                        <mnu:AppGridMenu ID="appGridMenu3" runat="server"></mnu:AppGridMenu>
                                    </td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        <div style="overflow: auto; width: 100%; height: 100%">
                                            <table id="tblSelected" style="table-layout: fixed; font-size: 9pt; width: 100%;
                                                font-family: 宋体; border-collapse: collapse" onclick="handleClick();" cellspacing="0"
                                                cellpadding="0" width="100%" border="0" MultiSelect="true">
                                                <tr height="21" allowselect="0" align="center">
                                                    <td width="40px" class="bar">序号
                                                    </td>
                                                    <td class="bar">名称
                                                    </td>
                                                    <td width="50px" class="bar">分隔符
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" colspan="3" class="wizbox1">
                            <table style="font-size: 9pt" height="100%" cellspacing="0" cellpadding="0" width="100%">
                                <tr height="1">
                                    <td>
                                        <mnu:AppGridMenu ID="appGridMenu4" runat="server"></mnu:AppGridMenu>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center">
                                        <input id="inpAll" coding="" type="text" style="width:80%" readonly />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-left:20px">
                            <button style="width: 70px" onclick="window.returnValue = '';window.close();" id="Button2" type="button">
                                返回空值</button>
                        </td>
                        <td align="right" colspan="2">
                            <button style="width: 70px" onclick="okClick()" id="btnOk" type="button">
                                确 定</button>&nbsp;
                            <button style="width: 70px" onclick="parent.window.close();" type="button">
                                取 消</button>&nbsp;&nbsp;
                        </td>
                    </tr>
                </table>
            </td>
            <td width="5">
            </td>
        </tr>
    </table>
    </form>
</body>
</html>